package cn.demo.um.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.um.domain.UmAttrConf;
import cn.demo.um.service.IUmAttrConfService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 用户属性配置Controller
 *
 * @author xtjun
 * @date 2024-06-04
 */
@Tag(name = "用户属性配置")
@RestController
@RequestMapping("/um/umAttrConf")
public class UmAttrConfController extends BaseController {
    @Resource
    private IUmAttrConfService umAttrConfService;

    @Operation(summary = "查询用户属性配置列表")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:list')")
    @GetMapping("/list")
    public PageR<UmAttrConf> list(UmAttrConf umAttrConf, PageQuery pageQuery) {
        Page<UmAttrConf> page = umAttrConfService.selectUmAttrConfPage(umAttrConf, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出用户属性配置列表")
    @GetMapping("/all")
    public R<List<UmAttrConf>> all() {
        List<UmAttrConf> list = umAttrConfService.selectUmAttrConfAll();
        return R.ok(list);
    }

    @Operation(summary = "导出用户属性配置列表")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:export')")
    @Log(title = "用户属性配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UmAttrConf umAttrConf) {
        List<UmAttrConf> list = umAttrConfService.selectUmAttrConfList(umAttrConf);
        ExcelUtil<UmAttrConf> util = new ExcelUtil<UmAttrConf>(UmAttrConf.class);
        util.exportExcel(response, list, "用户属性配置数据");
    }

    @Operation(summary = "获取用户属性配置详细信息")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:query')")
    @GetMapping(value = "/{id}")
    public R<UmAttrConf> getInfo(@PathVariable("id") String id) {
        return R.ok(umAttrConfService.selectUmAttrConfById(id));
    }

    @Operation(summary = "新增用户属性配置")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:add')")
    @Log(title = "用户属性配置", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UmAttrConf umAttrConf) {
        return toAjax(umAttrConfService.insertUmAttrConf(umAttrConf));
    }

    @Operation(summary = "修改用户属性配置")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:edit')")
    @Log(title = "用户属性配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UmAttrConf umAttrConf) {
        return toAjax(umAttrConfService.updateUmAttrConf(umAttrConf));
    }

    @Operation(summary = "删除用户属性配置")
    @PreAuthorize("@ss.hasPermi('um:umAttrConf:remove')")
    @Log(title = "用户属性配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(umAttrConfService.deleteUmAttrConfByIds(ids));
    }
}
